﻿using System.Text.RegularExpressions;
using YAF.Controls;

namespace YAF.Editors
{
    public abstract class BaseForumEditor : BaseControl, IBaseEditorModule
    {
        protected string _baseDir = string.Empty;

        protected RegexOptions _options = RegexOptions.IgnoreCase | RegexOptions.Multiline;

        #region IBaseEditorModule Members

        public abstract bool Active
        {
            get;
        }

        public abstract string Description
        {
            get;
        }

        public virtual int ModuleId
        {
            get
            {
                return Description.GetHashCode();
            }
        }

        #endregion

        public new string ResolveUrl(string relativeUrl)
        {
            if (this._baseDir != string.Empty)
            {
                return this._baseDir + relativeUrl;
            }

            return base.ResolveUrl(relativeUrl);
        }

        protected virtual string Replace(string txt, string match, string replacement)
        {
            while (Regex.IsMatch(txt, match, this._options))
            {
                txt = Regex.Replace(txt, match, replacement, this._options);
            }

            return txt;
        }

        #region Virtual Properties
        public abstract string Text
        {
            get;
            set;
        }

        public virtual string BaseDir
        {
            set
            {
                this._baseDir = value;
                if (!this._baseDir.EndsWith("/"))
                {
                    this._baseDir += "/";
                }
            }
        }

        public virtual string StyleSheet
        {
            get
            {
                return string.Empty;
            }
            set
            {
                ;
            }
        }

        public virtual bool UsesHTML
        {
            get
            {
                return false;
            }
        }

        public virtual bool UsesBBCode
        {
            get
            {
                return false;
            }
        }
        #endregion
    }
}
